package com.mmdccj.yugu.mapper;

import com.mmdccj.yugu.dto.CommentDto;
import com.mmdccj.yugu.entity.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: star_
 * @date: 2023-12-11 20:16
 */
@Mapper
public interface CommentMapper {
    // 创建评论
    @Insert("insert into comment (id, content, likes, create_time, user_id, type, type_id, commented_id) values (#{id} , #{content}, 0, #{createTime}, #{userId}, #{type}, #{typeId}, #{commentedId})")
    void insertComment(Comment comment);

    //获取最新评论
    List<CommentDto> selectCommentsByTypeAndTypeIdAscByTime(String type, String typeId);

    //获取点赞多的评论
    List<CommentDto> selectCommentsByTypeAndTypeIdDescByLikes(String type, String typeId);

    @Select("SELECT COUNT(*) FROM user_like_comment WHERE comment_id=#{commentId} AND user_Id=#{userId}")
    int checkLike(String userId, String commentId);

    @Select("SELECT likes FROM user_comment WHERE id=#{commentId}")
    Integer like(String commentId);

    @Update("UPDATE comment SET likes=#{likes} WHERE id=#{commentId}")
    void updateLike(String commentId, int likes);

    @Insert("INSERT INTO user_like_comment(user_id,comment_id) VALUES(#{userId},#{commentId})")
    void insertLikeTo(String userId, String commentId);

    @Delete("DELETE FROM comment WHERE type_id=#{id} AND type=#{type}")
    void deleteComment(String id, String type);
}
